#pragma once

#include "BasicType.h"
#include "Character.h"
#include "SceneObject.h"
#include "Parser.h"
#include "DisplayList.h"
#include "ActionRecord.h"
#include "As2VirtualMachine.h"

namespace LightPlayer {



	class TimelineObject : public SceneObject, public Parser {
	protected:
		Stream										m_Stream;
		Parser*										m_pParent;
		CharacterList*								m_pCharacterList;
		pool<SceneObject>*							m_pObjectPool;
		pool<TimelineObject>*						m_pTimelineObjectPool;
		As2VM*										m_pAs2VM;
		var_list_type								m_VarList;
		DisplayList									m_DsiplayList;
		ActionList									m_ActionList;
		FrameLabelList								m_FrameLabelList;

		uint32										m_ActualFrame;
		uint32										m_FrameCount;
		bool										m_IsPlaying;
		bool										m_Visible;
		As2Var										m_As2Name;

	public:
													TimelineObject();
		virtual										~TimelineObject(){};
		virtual	void								init();
		virtual void								SetParent(Parser* pParent);
				void								SetCharacterList(CharacterList* _characterList)								{ m_pCharacterList = _characterList;}
				void								SetObjectPool(pool<SceneObject>* _pObjectPool)								{ m_pObjectPool = _pObjectPool;}
				void								SetTimelineObjectPool(pool<TimelineObject>* _pTimelineObjectPool)			{ m_pTimelineObjectPool = _pTimelineObjectPool;}
				void								SetAs2VM(As2VM* pAs2VM)														{ m_pAs2VM = pAs2VM; }

		virtual void								setCharacter(Character* character);
		virtual void								update(float dt);
		virtual void								draw(LightAbstractRenderer* pRenderer);
		virtual eSceneObjectType					getType()																	{return eTimelineObject;}
		virtual RECT								getBounds() const;
				void								cloneFromObject( TimelineObject* object, const char* name, uint16 depth, Parser* parent = NULL );
	
				void								setWidth(float _width);
				void								setHeight(float _height);
	private:
		void										collectFrameLabels();
		void										clearDisplayList();
	protected:
		virtual Stream*								getParserStream()										{return &m_Stream;};
		virtual CharacterList*						getCharacterList()										{return m_pCharacterList;};
		virtual pool<SceneObject>*					getObjectPool()											{return m_pObjectPool;};
		virtual pool<TimelineObject>*				getTimelineObjectPool()									{return m_pTimelineObjectPool;};
		virtual As2VM*								getAs2VM()												{return m_pAs2VM;}
		virtual DisplayList*						getDisplayList()										{return &m_DsiplayList;};
		virtual ActionList*							getActionList()											{return &m_ActionList;};
		virtual uint32								getFrameNumber()										{return m_FrameCount;};
		virtual uint32								getActualFrame()										{return m_ActualFrame;};
		virtual void								setActualFrame(uint32 frame)							{m_ActualFrame = frame;};
		virtual SceneObject*						getNewSceneObject();
		virtual TimelineObject*						getNewTimelineObject();
		virtual void								freeObject(SceneObject* object);
		virtual uint16								getFrameForLabel(const char* label);
		virtual Parser*								getParent()												{return m_pParent;};
		// as2 function
		virtual bool								isPlaying() const										{return m_IsPlaying;}
		virtual void								play()													{m_IsPlaying = true;}
		virtual void								stop()													{m_IsPlaying = false;}
		virtual As2Var								getVar(const char* name);
		virtual void								setVar( const char* name, const As2Var& value );
		virtual As2Var								getProperty( PropertyEnum property );
		virtual void								setProperty(PropertyEnum property, const As2Var& value );
	};
};